package com.lx.others.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class Others {

    @RequestMapping("others")
    String others(HttpServletRequest request){
        return "others" + request.getServerPort();
    }

    @Autowired
    RestTemplate restTemplate;
    @RequestMapping("others-user")
    String user(){
        return restTemplate.getForObject("http://cloud-user/user", String.class);
    }



    ////////////////////////////////////////////
    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping("sendMsg")
    public String sendMsg(String msg){
        for (int i = 0; i < 10; i++) {
            rabbitTemplate.convertAndSend("work.queue",msg + " " + i);
        }
        return "消息发送成功";
    }

    @RequestMapping("topicMsg")
    public String topicMsg(String msg, String key){
            rabbitTemplate.convertAndSend("topicEx", key, key + "---" +msg);
        return "消息发送成功";
    }

}
